import { PassportStrategy } from "@nestjs/passport";
import { Profile } from "passport";
import { Strategy } from "passport-google-oauth20";
import { SocksProxyAgent } from "socks-proxy-agent";

const Agent = new SocksProxyAgent(process.env.SOCKS5_PROXY ||'socks5://127.0.0.1:7890')
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
    constructor() {
        super({
            clientID: '6389036022-7hj1tkvevsdqhr7hgpuaoef6k917ujsj.apps.googleusercontent.com',
            clientSecret: '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',
            callbackURL: 'http://localhost:3000/login-user/callback/google',
            scope: ['email', 'profile'],
        })
        this._oauth2.setAgent(Agent)
    }
    validate(accessToken: string, refreshToken: string, profile: Profile) {
        const { name, emails, photos } = profile
        const user = {
            email: emails[0].value,
            firstName: name.givenName,
            lastName: name.familyName,
            picture: photos[0].value,
            accessToken
        }
        return user
    }
}